import { injectable, inject } from 'inversify';
import { IMessageService } from '../interfaces/IMessageService';
import { IMessageRepository } from '../../infrastructure/database/repositories/interfaces/IRepository';
import { Message } from '../../domain/entities/message.entity';
import { TYPES } from '../../infrastructure/ioc/types';

@injectable()
export class MessageService implements IMessageService {
  constructor(@inject(TYPES.MessageRepository) private messageRepository: IMessageRepository<Message>) {}

  async sendMessage(sessionId: string, senderId: string, content: string): Promise<Message> {
    const message = new Message();
    message.sessionId = sessionId;
    message.senderId = senderId;
    message.content = content;
    message.timestamp = new Date();
    return this.messageRepository.save(message);
  }

  async getChatHistory(sessionId: string): Promise<Message[]> {
    return this.messageRepository.findBySessionId(sessionId);
  }
}